(function() {
	window.register = {
		init: function() {
			this.tapEvent()
			this.telephone =/^\d{11}$/;
			this.pass = /^\S{6,12}$/
		},
		tapEvent: function() {
			//获取光标
			common.focu("input", "green")
			//获取验证码
			$(".mui-btn-primary").on("tap", function() {
				var phone = document.getElementsByClassName("phone")[0]
				var self = this
				if(!register.telephone.test(phone.value)) {
					mui.toast("请输入正确的手机号码!")
					return
				}
			
				common.ajax("student/sendVerifyCode", {
					phone: phone.value,
					type: 1
				}, function(data) {
					if(data.code == 200) {
						common.countdown(self, 60, "#ababab", "#40CC8B","重新获取")
						mui.toast("发送成功!")
					} else {
						mui.toast(data.message)
					}
					console.log(data)
				})
			})
			//上去光标判断重新输入密码
			$("#surepassword").on("blur", function() {
				judgement()
			})
			$("#password").on("blur", function() {
				judgement()
			})

			function judgement() {
				if(!($("#surepassword").val() == "" || $("#password").val() == "")) {
					if(!(register.pass.test($("#surepassword").val()) && register.pass.test($("#password").val()))) {
						mui.toast("请输入6到12位的密码!")
						return
					}
					if($("#password").val() != $("#surepassword").val()) {
						mui.toast("密码错误!")
						return
					}
				}
			}
			//下一步
			$(".next-button").on("tap", function() {
				var phone = document.getElementsByClassName("phone")[0];
				var verify=document.getElementById("verify");
				if(!register.telephone.test(phone.value)) {
					mui.toast("请输入正确的手机号码!")
					return
				}
				if($("#verify").val() == "") {
					mui.toast("验证码不能为空!")
					return
				}
				if($("#surepassword").val() == "" && $("#password").val() == "") {
					mui.toast("密码不能为空!")
					return
				}
				if(!(register.pass.test($("#surepassword").val()) && register.pass.test($("#password").val()))) {
					mui.toast("请输入6到12位的密码!")
					return
				}
				if($("#password").val() != $("#surepassword").val()) {
					mui.toast("密码错误!")
					return
				}
				
				common.ajax("student/register", {
					phone: phone.value,
					type: 1,
					code:verify.value,
					password1: $("#password").val(),
					password2: $("#surepassword").val()
				}, function(data) {
					if(data.code == 200) {
						localStorage.setItem("data", JSON.stringify(data.data))
						common.open("message.html","")
					} else {
						mui.toast(data.message)
					}
				})
			})
		}
	}
	register.init()
})()